package com.solarfridge.monitor.shared.data;

import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * Class which contains basic information
 * about the fridge such as, id.
 *
 */
@PersistenceCapable
public class Fridge implements IsSerializable {
	
	/** The Fridge id. 
	 * should always be changed from the defaultID
	 * as it acts as the primary key
	 * of the Fridge Object*/
	@PrimaryKey
	private String mFridgeId = "defaultID";	
	
	/** The Date added. */
	@Persistent
	private long mDateAdded = System.currentTimeMillis();
	
	/** Is Logging enabled. */
	@Persistent
	private boolean mLoggingEnabled = false;
	
	@Persistent
	private FridgeData mLastUpdate = new FridgeData("", 0, 0, 0, 0, -1);
	
	/**
	 * Instantiates a new fridge.
	 */
	@SuppressWarnings("unused")
	private Fridge(){
		//required for IsSerializable
	}
	
	/**
	 * Instantiates a new fridge.
	 *
	 * @param id the id
	 */
	public Fridge(String id) {
		setFridgeId(id);
	}
	
	/**
	 * Instantiates a new fridge.
	 *
	 * @param id the id
	 */
	public Fridge(String id, boolean loggingEnabled) {
		setFridgeId(id);
		setLoggingEnabled(loggingEnabled);
	}

	/**
	 * Updates the statistics about the fridge
	 * to the specified fridge data object.
	 * Updates: last checkin, cur temps, etc.
	 * @param data
	 * @return 
	 */
	public void updateData(FridgeData data){
		mLastUpdate = data;
	}
	
	
	/**
	 * Gets the fridge id.
	 *
	 * @return the fridge id
	 */
	public String getFridgeId() {
		return mFridgeId;
	}

	/**
	 * Sets the fridge id.
	 *
	 * @param fridgeId the new fridge id
	 */
	public void setFridgeId(String fridgeId) {
		mFridgeId = fridgeId;
	}

	/**
	 * Gets the last checkin.
	 *
	 * @return the last checkin
	 */
	public long getLastCheckin() {
		return mLastUpdate.getTimeStamp();
	}
	
	public double getCurATemp () {
		return mLastUpdate.getATemp();
	}
	
	public double getCurFTemp () {
		return mLastUpdate.getFTemp();
	}
	
	public double getCurCTemp () {
		return mLastUpdate.getCTemp();
	}
	
	public double getCurCSun () {
		return mLastUpdate.getCSun();
	}

	/**
	 * Gets the current temp.
	 *
	 * @return the current temp
	 */

	/**
	 * Gets the date added.
	 *
	 * @return the date added
	 */
	public long getDateAdded() {
		return mDateAdded;
	}

	/**
	 * Sets the date added.
	 *
	 * @param dateAdded the new date added
	 */
	public void setDateAdded(long dateAdded) {
		mDateAdded = dateAdded;
	}

	/**
	 * Checks if logging is enabled.
	 *
	 * @return true, if is logging enabled
	 */
	public boolean isLoggingEnabled() {
		return mLoggingEnabled;
	}

	/**
	 * Sets the logging enabled.
	 *
	 * @param loggingEnabled the new logging enabled
	 */
	public void setLoggingEnabled(boolean loggingEnabled) {
		mLoggingEnabled = loggingEnabled;
	}
	
	
}
